package com.google.code.dhillon;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class CharacterBiography extends Activity {
	private static final String TAG = CharacterBiography.class.getSimpleName();

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bio);

		LostDbAdapter dbHelper = new LostDbAdapter(this);
		dbHelper.open();

		// fetch the passed in row id
		Bundle extras = getIntent().getExtras();
		Long rowId = extras != null ? extras.getLong(LostDbAdapter.KEY_ROWID) : null;
		if (rowId != null) {
			Cursor c = dbHelper.fetchCharacter(rowId);
			startManagingCursor(c);

			// fill view
			TextView nameTextView = (TextView) findViewById(R.id.name);
			TextView bioTextView = (TextView) findViewById(R.id.text);

			// if we had more than one result, we could use a while loop to
			// iterate through the cursor by repeatedly calling moveToNext()
			nameTextView.setText(c.getString(c.getColumnIndex(LostDbAdapter.KEY_NAME)));
			bioTextView.setText(c.getString(c.getColumnIndex(LostDbAdapter.KEY_BIO)));
		} else {
			// error, they didn't pass in a row id
			Log.e(TAG, "You forgot to pass in a row id.");
		}
	}
}
